package com.vote.www.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.vote.www.core.page.Pagination;
import com.vote.www.domain.Czjdataresource;
import com.vote.www.domain.Czjuserapprove;
import com.vote.www.persistence.CzjdatasuMapper;

import tangwj.person.dao.ResourceDao;

/**
 * 
 * CzjdatasuService 创建人:cheny 时间：2017年5月16日-下午4:49:08
 * 
 * @version 1.0.0
 *
 */
@Service
public class CzjdatasuService {
	@Autowired
	private ResourceDao resourceDao;
	@Resource
	private JdbcTemplate jdbcTemplate;
	@Resource
	private CzjdatasuMapper  czjdatasuMapper;
	public Pagination list(int pageNo, int pageSize) {
	    if(pageSize==0){
            pageSize = 20;
        }
        Pagination pagination = new Pagination();
        pagination.setPageNo(pageNo);
        pagination.setPageSize(pageSize);
        Map<String, Object> param = new HashMap<String, Object>();
        param.putAll(pagination.toMap());
        int count = czjdatasuMapper.getTotalRows(param);
        pagination.setTotalCount(count);
        List<Map<String, Object>> list = czjdatasuMapper.getList(param);
        pagination.setList(list);
        return pagination;
	}
	public Czjdataresource findById(String dataresourceId) throws Exception {
		
		 
			return (Czjdataresource)   jdbcTemplate.queryForObject("select * from czj_dataresource where dataresourceId='"+dataresourceId+"'",new BeanPropertyRowMapper(Czjdataresource.class));
		
	}
	public void updateCzjdatasu(Czjdataresource czjdataresource) throws Exception {
		
		jdbcTemplate.update("update  czj_dataresource set name='"+czjdataresource.getName()+"',value='"+czjdataresource.getValue()+"',title='"+czjdataresource.getTitle()+"',codename='"+czjdataresource.getCodename()+"' where dataresourceId='"+czjdataresource.getDataresourceId()+"'");
	}
	
	
}
